package cn.wolfcode.p2p.controller;

import cn.wolfcode.p2p.base.exception.CustomerException;
import cn.wolfcode.p2p.base.query.VideoAuthQuery;
import cn.wolfcode.p2p.base.service.IVideoAuthServie;
import cn.wolfcode.p2p.util.JsonResult;
import cn.wolfcode.p2p.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class VedioAuthController {
    @Autowired
    private IVideoAuthServie videoAuthServie;

    /**
     * 视频审核列表
     * @param model
     * @return
     */
    @RequestMapping("vedioAuth")
    public String vedioAuth(@ModelAttribute("qo") VideoAuthQuery qo, Model model){
        if (!"admin".equals(UserContext.getCurrentUser().getUsername())) {
            qo.setAuditorId(UserContext.getCurrentUser().getId());
        }
        model.addAttribute("pageInfo", videoAuthServie.query(qo));
        return "vedioAuth/list";
    }

    @RequestMapping("vedioAuth_audit")
    @ResponseBody
    public JsonResult audit(Long id, Integer state, String remark){
        JsonResult jsonResult = new JsonResult();
        try {
            videoAuthServie.audit(id, state, remark);
        } catch (CustomerException e) {
            jsonResult.setMessage(e.getMessage());
            throw new CustomerException(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("系统繁忙中,请稍后再试");
        }
        return jsonResult;
    }
}
